package com.hnchances.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hnchances.entity.Grades;
import com.hnchances.mapper.ScoreMapper;
import com.hnchances.service.ScoreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ScoreServiceImpl implements ScoreService {

    @Autowired
    private ScoreMapper scoreMapper;

    @Override
    public void addScore(Grades grades) {
        scoreMapper.insert(grades);
    }

    @Override
    public void updateScore(Grades grades) {
        scoreMapper.update(grades);
    }

    @Override
    public void deleteScore(Long id) {
        scoreMapper.deleteById(id);
    }

    @Override
    public Grades getScoreById(Long id) {
        return scoreMapper.selectById(id);
    }

    @Override
    public PageInfo<Map<String, Object>> queryScores(String studentName,
                                                     String className,
                                                     String courseName,
                                                     String examName,
                                                     int pageNum,
                                                     int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> list =
                scoreMapper.selectByCondition(studentName, className, courseName, examName);
        return new PageInfo<>(list);
    }
}